package tv.youxing.android.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;

import com.kymjs.rxvolley.RxVolley;
import com.kymjs.rxvolley.client.HttpCallback;
import com.kymjs.rxvolley.client.HttpParams;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import tv.youxing.android.Interface.CustomToobarImp;
import tv.youxing.android.R;
import tv.youxing.android.adapter.MoreClassificationAdapter;
import tv.youxing.android.custom.CustomToolbar;
import tv.youxing.android.entity.MoreClassificationModel;
import tv.youxing.android.utils.GsonUtils;
import tv.youxing.android.utils.PicassoUtils;
import tv.youxing.android.utils.StaticClass;


/**
 * 更多分类
 */
public class MoreClassificationActivity extends BaseActivity {

    @BindView(R.id.top_iv)
    ImageView topIv;
    @BindView(R.id.gv)
    GridView gv;
    @BindView(R.id.tb)
    CustomToolbar mCustomToolbar;


    private MoreClassificationModel.ResultBean.AdBean mAbsList;
    private MoreClassificationModel mAllData;
    private List<MoreClassificationModel.ResultBean.AlbumClassifysBean> mAlnumDataList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_more_classification);
        ButterKnife.bind(this);


        mCustomToolbar.setBackClickLister(new CustomToobarImp.back() {
            @Override
            public void onclick() {
                finish();
            }
        });

        loadData();
    }

    void loadData() {
//post请求简洁版实现
        HttpParams params = new HttpParams();

        RxVolley.post(StaticClass.MoreClassification, params, new HttpCallback() {
            @Override
            public void onSuccess(String t) {
                mAllData = GsonUtils.GsonToBean(t, MoreClassificationModel.class);
                mAbsList = mAllData.getResult().getAd();
                mAlnumDataList = mAllData.getResult().getAlbum_classifys();


                initAbs();
                initData();
            }
        });
    }

    void initAbs() {
        PicassoUtils.loadImageView(this,mAbsList.getCover(),topIv);
    }

    void initData() {
        gv.setAdapter(new MoreClassificationAdapter(this,mAlnumDataList));

        gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent3 = new Intent(MoreClassificationActivity.this, ZhuanJiFenLeiActivity.class);
                intent3.putExtra("album_classify_id",mAllData.getResult().getAlbum_classifys().get(i).getAlbum_classify_id()+"");
                startActivity(intent3);
            }
        });


        topIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent5 = new Intent(MoreClassificationActivity.this, AdvertisementWEBActivity.class);
                intent5.putExtra("url",mAllData.getResult().getAd().getGo_to_url());
                MoreClassificationActivity.this.startActivity(intent5);
            }
        });
    }
}
